package com.JavaNet.chapter7_urlConnection;

import java.io.*;
import java.net.*;

public class AllHeaders {

    private static final String oreilly = "https://www.oreilly.com/";
    private static final String baidu = "https://www.baidu.com/";

    public static void show(String[] args) {
        for (int i = 0; i < args.length; i++) {
            try {
                URL u = new URL(args[i]);
                URLConnection uc = u.openConnection();
                for (int j = 1; ; j++) {
                    String header = uc.getHeaderField(j);
                    if (header == null) break;
                    System.out.println(uc.getHeaderFieldKey(j) + ": " + header);
                }
            } catch (MalformedURLException ex) {
                System.err.println(args[i] + " is not a URL I understand.");
            } catch (IOException ex) {
                System.err.println(ex);
            }
            System.out.println();
        }
    }

    public static void main(String[] args) {
        String[] strings = new String[2];
        strings[0] = baidu;
        strings[1] = oreilly;

        show(strings);


    }

}
